package com.lyk.coursearrange.controller;

import com.lyk.coursearrange.common.log.annotation.Log;
import com.lyk.coursearrange.common.log.enums.OperationType;
import com.lyk.coursearrange.entity.PaymentResult;
import com.lyk.coursearrange.service.PaymentResultService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/payments")
public class PaymentResultController {

    @Autowired
    private PaymentResultService paymentService;

    @PostMapping
    public PaymentResult processPayment(@RequestParam boolean diagnosticFeePaid,
                                        @RequestParam double totalAmount,
                                        @RequestParam int installmentNumber) {
        return paymentService.processPayment(diagnosticFeePaid, totalAmount, installmentNumber);
    }
    @PostMapping("/add")
    @Log(title = "新增全款分期付款记录成功", operationType = OperationType.INSERT)
    public String addPaymentResult(@RequestBody PaymentResult paymentResult) {
        paymentService.addPaymentResult(paymentResult);
        return "新增全款分期付款记录成功";
    }

    /***
     * 根据id查询全款分期付款记录
     * @param id
     * @return
     */
    @GetMapping("/get/{id}")
    @Log(title = "根据id查询全款分期付款记录", operationType = OperationType.SELECT)
    public PaymentResult getPaymentResultById(@PathVariable("id") Long id) {
        return paymentService.getPaymentResultById(id);
    }

    /***
     * 查询所有全款分期付款
     * @return
     */
    @GetMapping("/get/all")
    @Log(title = "查询所有全款分期付款", operationType = OperationType.SELECT)
    public List<PaymentResult> getAllPaymentResults() {
        return paymentService.getAllPaymentResults();
    }

    /***
     * 更新全款分期付款记录
     * @param paymentResult
     * @return
     */
    @PutMapping("/update")
    @Log(title = "更新全款分期付款记录", operationType = OperationType.UPDATE)
    public String updatePaymentResult(@RequestBody PaymentResult paymentResult) {
        paymentService.updatePaymentResult(paymentResult);
        return "更新全款分期付款记录成功";
    }

    /***
     * 根据id删除全款分期记录
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    @Log(title = "根据id删除全款分期记录", operationType = OperationType.DELETE)
    public String deletePaymentResultById(@PathVariable("id") Long id) {
        paymentService.deletePaymentResultById(id);
        return "删除全款分期付款记录成功";
    }

}

